package com.todod.base.module.base.controller.admin.wits8;

import com.todod.base.module.base.controller.admin.rtmaintain.rtmaintainchild.vo.RtMaintainChildPageReqVO;
import com.todod.base.module.base.controller.admin.rtmaintain.rtmaintainchild.vo.RtMaintainChildRespVO;
import com.todod.base.module.base.dal.dataobject.rtmaintain.rtmaintainchild.RtMaintainChildDO;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.todod.base.framework.common.pojo.PageParam;
import com.todod.base.framework.common.pojo.PageResult;
import com.todod.base.framework.common.pojo.CommonResult;
import com.todod.base.framework.common.util.object.BeanUtils;
import static com.todod.base.framework.common.pojo.CommonResult.success;

import com.todod.base.framework.excel.core.util.ExcelUtils;

import com.todod.base.framework.apilog.core.annotation.ApiAccessLog;
import static com.todod.base.framework.apilog.core.enums.OperateTypeEnum.*;

import com.todod.base.module.base.controller.admin.wits8.vo.*;
import com.todod.base.module.base.dal.dataobject.wits8.WITS8DO;
import com.todod.base.module.base.service.wits8.WITS8Service;

@Tag(name = "管理后台 - WITS8生成的表")
@RestController
@RequestMapping("/base/wits8")
@Validated
public class WITS8Controller {

    @Resource
    private WITS8Service wITS8Service;


    @RequestMapping("/getnewone")
    @Operation(summary = "按照要求取一条最新数据")
    public CommonResult<WITS8RespVO> getNewOne(@Valid WITS8PageReqVO reqVO) {
        WITS8DO wits8DO = wITS8Service.getNewOne( reqVO );
        return success(BeanUtils.toBean(wits8DO, WITS8RespVO.class));
    }

    @RequestMapping("/getnewlist")
    @Operation(summary = "按照要求查询列表")
    public CommonResult<List<WITS8RespVO>> getNewList(@Valid WITS8PageReqVO reqVO) {
        List<WITS8DO> wits8DOList = wITS8Service.getNewList( reqVO );
        return success(BeanUtils.toBean(wits8DOList, WITS8RespVO.class));
    }







    @PostMapping("/create")
    @Operation(summary = "创建WITS8生成的表")
    public CommonResult<Long> createWITS8(@Valid @RequestBody WITS8SaveReqVO createReqVO) {
        return success(wITS8Service.createWITS8(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新WITS8生成的表")
    public CommonResult<Boolean> updateWITS8(@Valid @RequestBody WITS8SaveReqVO updateReqVO) {
        wITS8Service.updateWITS8(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除WITS8生成的表")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteWITS8(@RequestParam("id") Long id) {
        wITS8Service.deleteWITS8(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得WITS8生成的表")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<WITS8RespVO> getWITS8(@RequestParam("id") Long id) {
        WITS8DO wITS8 = wITS8Service.getWITS8(id);
        return success(BeanUtils.toBean(wITS8, WITS8RespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得WITS8生成的表分页")
    public CommonResult<PageResult<WITS8RespVO>> getWITS8Page(@Valid WITS8PageReqVO pageReqVO) {
        PageResult<WITS8DO> pageResult = wITS8Service.getWITS8Page(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WITS8RespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出WITS8生成的表 Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportWITS8Excel(@Valid WITS8PageReqVO pageReqVO,
                                 HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<WITS8DO> list = wITS8Service.getWITS8Page(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "WITS8生成的表.xls", "数据", WITS8RespVO.class,
                BeanUtils.toBean(list, WITS8RespVO.class));
    }

}